<template>
    <div class="nav-bar" :class="{'if_Fixed':isFixed}">
      <div class="container">
        <div class="pro-left">
          <div class="pro-title">
            {{title}}
          </div>
        </div>
        <div class="pro-right">
          <a href="">概述</a><span>|</span>
          <a href="">参数</a><span>|</span>
          <a href="">用户评价</a>
          <slot name="buy"></slot>
        </div>
      </div>
    </div>
</template>

<script>
export default {
  name: 'ProductParam',
  props: {
    title: String
  },
  data() {
    return {
      isFixed: false
    }
  },
  mounted() {
    window.addEventListener('scroll', this.initHeight)
  },
  methods: {
    initHeight() {
      let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
      this.isFixed = scrollTop > 152
    }
  },
  // 生命周期函数 销毁组件
  destroyed () {
    window.removeEventListener('scroll', this.initHeight)
  }
}
</script>

<style scoped lang="scss">
@import "./../assets/scss/mixin.scss";
@import "./../assets/scss/config.scss";
.nav-bar{
  height: 70px;
  line-height: 70px;
  border: 1px solid $colorH;
  border-bottom: none;
  z-index: 10;
  &.if_Fixed {
    position: fixed;
    top: 0;
    width: 100%;
    background-color: #fff;
    box-shadow: 0 5px 5px #cccccc;
  }
  .container{
    @include flex();
    .pro-title{
      font-size: 18px;
      color: $colorB;
      font-weight: bold;
    }
    .pro-right{
      font-size: 14px;
      a{
        color: $colorC;
      }
      span{
        margin: 0 10px;
      }
    }
  }
}
</style>
